# -*_ codeing=utf-8 -*-
# @Time: 2025/10/27 20:43
# @Author: foxhuty
# @File: create_data.py
# @Software: PyCharm
# @Based on python 3.10
from datetime import date
from decimal import Decimal
from sqlalchemy.orm import sessionmaker
from sqlalchemy_notes.db_main import engine
from sqlalchemy_notes.student_manager.models import Student, SexValue,Department

with sessionmaker(bind=engine).begin() as session:
    # add data
    stu1 = Student(name='Trump', salary=Decimal(1100), bonus=600,
                   gender=SexValue.MALE, entry_date=date.today())
    stu2 = Student(name='Obama', salary=Decimal(1800), bonus=500, gender=SexValue.MALE, entry_date=date(2015, 10, 25))
    # session.add(stu2)
    # session.add_all([stu1,stu2])
    # 类sql方法
    # insert_stmt= insert(Student).values(name="张本美和", gender=SexValue.FEMALE,salary=2000, bonus=300,entry_date=date(2025,10,25))
    # session.execute(insert_stmt)
    dept=Department(name='宜宾分公司',city='屏山')
    # stu1.dept=dept
    # stu2.dept=dept
    dept.student_list=[stu1,stu2]
    session.add(dept)